<?php
//Include Common Files @1-EF3EDF3D
define("RelativePath", ".");
define("PathToCurrentPage", "/");
define("FileName", "price_list.php");
include(RelativePath . "/Common.php");
include(RelativePath . "/Template.php");
include(RelativePath . "/Sorter.php");
include(RelativePath . "/Navigator.php");
//End Include Common Files

//Include Page implementation @16-3DD2EFDC
include_once(RelativePath . "/Header.php");
//End Include Page implementation

class clsGridprice { //price class @2-2AB01CB2

//Variables @2-CE86F781

    // Public variables
    var $ComponentType = "Grid";
    var $ComponentName;
    var $Visible;
    var $Errors;
    var $ErrorBlock;
    var $ds;
    var $DataSource;
    var $PageSize;
    var $SorterName = "";
    var $SorterDirection = "";
    var $PageNumber;

    var $CCSEvents = "";
    var $CCSEventResult;

    var $RelativePath = "";

    // Grid Controls
    var $StaticControls;
    var $RowControls;
    var $Sorter_Model;
    var $Sorter_Price;
    var $Sorter_offer;
//End Variables

//Class_Initialize Event @2-8C4DFC0E
    function clsGridprice($RelativePath, & $Parent)
    {
        global $FileName;
        global $CCSLocales;
        global $DefaultDateFormat;
        $this->ComponentName = "price";
        $this->Visible = True;
        $this->Parent = & $Parent;
        $this->RelativePath = $RelativePath;
        $this->Errors = new clsErrors();
        $this->ErrorBlock = "Grid price";
        $this->DataSource = new clspriceDataSource($this);
        $this->ds = & $this->DataSource;
        $this->PageSize = CCGetParam($this->ComponentName . "PageSize", "");
        if(!is_numeric($this->PageSize) || !strlen($this->PageSize))
            $this->PageSize = 20;
        else
            $this->PageSize = intval($this->PageSize);
        if ($this->PageSize > 100)
            $this->PageSize = 100;
        if($this->PageSize == 0)
            $this->Errors->addError("<p>Form: Grid " . $this->ComponentName . "<br>Error: (CCS06) Invalid page size.</p>");
        $this->PageNumber = intval(CCGetParam($this->ComponentName . "Page", 1));
        if ($this->PageNumber <= 0) $this->PageNumber = 1;
        $this->SorterName = CCGetParam("priceOrder", "");
        $this->SorterDirection = CCGetParam("priceDir", "");

        $this->Model = & new clsControl(ccsLink, "Model", "Model", ccsText, "", CCGetRequestParam("Model", ccsGet), $this);
        $this->Model->Page = "price_maint.php";
        $this->Price = & new clsControl(ccsLabel, "Price", "Price", ccsInteger, "", CCGetRequestParam("Price", ccsGet), $this);
        $this->offer = & new clsControl(ccsCheckBox, "offer", "offer", ccsInteger, "", CCGetRequestParam("offer", ccsGet), $this);
        $this->offer->CheckedValue = $this->offer->GetParsedValue(1);
        $this->offer->UncheckedValue = $this->offer->GetParsedValue(0);
        $this->Sorter_Model = & new clsSorter($this->ComponentName, "Sorter_Model", $FileName, $this);
        $this->Sorter_Price = & new clsSorter($this->ComponentName, "Sorter_Price", $FileName, $this);
        $this->Sorter_offer = & new clsSorter($this->ComponentName, "Sorter_offer", $FileName, $this);
        $this->price_Insert = & new clsControl(ccsLink, "price_Insert", "price_Insert", ccsText, "", CCGetRequestParam("price_Insert", ccsGet), $this);
        $this->price_Insert->Parameters = CCGetQueryString("QueryString", array("Model", "ccsForm"));
        $this->price_Insert->Page = "price_maint.php";
        $this->Navigator = & new clsNavigator($this->ComponentName, "Navigator", $FileName, 10, tpSimple, $this);
    }
//End Class_Initialize Event

//Initialize Method @2-90E704C5
    function Initialize()
    {
        if(!$this->Visible) return;

        $this->DataSource->PageSize = & $this->PageSize;
        $this->DataSource->AbsolutePage = & $this->PageNumber;
        $this->DataSource->SetOrder($this->SorterName, $this->SorterDirection);
    }
//End Initialize Method

//Show Method @2-216CF7B4
    function Show()
    {
        global $Tpl;
        global $CCSLocales;
        if(!$this->Visible) return;

        $ShownRecords = 0;


        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeSelect", $this);


        $this->DataSource->Prepare();
        $this->DataSource->Open();

        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShow", $this);
        if(!$this->Visible) return;

        $GridBlock = "Grid " . $this->ComponentName;
        $ParentPath = $Tpl->block_path;
        $Tpl->block_path = $ParentPath . "/" . $GridBlock;


        if(($ShownRecords < $this->PageSize) && $this->DataSource->next_record())
        {
            do {
                $this->DataSource->SetValues();
                $Tpl->block_path = $ParentPath . "/" . $GridBlock . "/Row";
                if(!is_array($this->offer->Value) && !strlen($this->offer->Value) && $this->offer->Value !== false)
                    $this->offer->SetValue(false);
                $this->Model->SetValue($this->DataSource->Model->GetValue());
                $this->Model->Parameters = CCGetQueryString("QueryString", array("ccsForm"));
                $this->Model->Parameters = CCAddParam($this->Model->Parameters, "Model", $this->DataSource->f("Model"));
                $this->Price->SetValue($this->DataSource->Price->GetValue());
                $this->offer->SetValue($this->DataSource->offer->GetValue());
                $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShowRow", $this);
                $this->Model->Show();
                $this->Price->Show();
                $this->offer->Show();
                $Tpl->block_path = $ParentPath . "/" . $GridBlock;
                $Tpl->parse("Row", true);
                $ShownRecords++;
            } while (($ShownRecords < $this->PageSize) && $this->DataSource->next_record());
        }
        else // Show NoRecords block if no records are found
        {
            $Tpl->parse("NoRecords", false);
        }

        $errors = $this->GetErrors();
        if(strlen($errors))
        {
            $Tpl->replaceblock("", $errors);
            $Tpl->block_path = $ParentPath;
            return;
        }
        $this->Navigator->PageNumber = $this->DataSource->AbsolutePage;
        if ($this->DataSource->RecordsCount == "CCS not counted")
            $this->Navigator->TotalPages = $this->DataSource->AbsolutePage + ($this->DataSource->next_record() ? 1 : 0);
        else
            $this->Navigator->TotalPages = $this->DataSource->PageCount();
        $this->Sorter_Model->Show();
        $this->Sorter_Price->Show();
        $this->Sorter_offer->Show();
        $this->price_Insert->Show();
        $this->Navigator->Show();
        $Tpl->parse();
        $Tpl->block_path = $ParentPath;
        $this->DataSource->close();
    }
//End Show Method

//GetErrors Method @2-FEA69710
    function GetErrors()
    {
        $errors = "";
        $errors = ComposeStrings($errors, $this->Model->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Price->Errors->ToString());
        $errors = ComposeStrings($errors, $this->offer->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Errors->ToString());
        $errors = ComposeStrings($errors, $this->DataSource->Errors->ToString());
        return $errors;
    }
//End GetErrors Method

} //End price Class @2-FCB6E20C

class clspriceDataSource extends clsDBConnection1 {  //priceDataSource Class @2-B8B1AE73

//DataSource Variables @2-27079D07
    var $Parent = "";
    var $CCSEvents = "";
    var $CCSEventResult;
    var $ErrorBlock;
    var $CmdExecution;

    var $CountSQL;
    var $wp;


    // Datasource fields
    var $Model;
    var $Price;
    var $offer;
//End DataSource Variables

//DataSourceClass_Initialize Event @2-2C23C3BA
    function clspriceDataSource(& $Parent)
    {
        $this->Parent = & $Parent;
        $this->ErrorBlock = "Grid price";
        $this->Initialize();
        $this->Model = new clsField("Model", ccsText, "");
        $this->Price = new clsField("Price", ccsInteger, "");
        $this->offer = new clsField("offer", ccsInteger, "");

    }
//End DataSourceClass_Initialize Event

//SetOrder Method @2-C6B782F8
    function SetOrder($SorterName, $SorterDirection)
    {
        $this->Order = "Price";
        $this->Order = CCGetOrder($this->Order, $SorterName, $SorterDirection, 
            array("Sorter_Model" => array("Model", ""), 
            "Sorter_Price" => array("Price", ""), 
            "Sorter_offer" => array("offer", "")));
    }
//End SetOrder Method

//Prepare Method @2-14D6CD9D
    function Prepare()
    {
        global $CCSLocales;
        global $DefaultDateFormat;
    }
//End Prepare Method

//Open Method @2-70001880
    function Open()
    {
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeBuildSelect", $this->Parent);
        $this->CountSQL = "SELECT COUNT(*) " .
        "FROM price";
        $this->SQL = "SELECT price.Model, price.Price, price.offer  " .
        "FROM price {SQL_Where} {SQL_OrderBy}";
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeExecuteSelect", $this->Parent);
        if ($this->CountSQL) 
            $this->RecordsCount = CCGetDBValue(CCBuildSQL($this->CountSQL, $this->Where, ""), $this);
        else
            $this->RecordsCount = "CCS not counted";
        $this->query($this->OptimizeSQL(CCBuildSQL($this->SQL, $this->Where, $this->Order)));
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "AfterExecuteSelect", $this->Parent);
    }
//End Open Method

//SetValues Method @2-0F8B4FD8
    function SetValues()
    {
        $this->Model->SetDBValue($this->f("Model"));
        $this->Price->SetDBValue(trim($this->f("Price")));
        $this->offer->SetDBValue(trim($this->f("offer")));
    }
//End SetValues Method

} //End priceDataSource Class @2-FCB6E20C

//Include Page implementation @17-58DBA1E3
include_once(RelativePath . "/Footer.php");
//End Include Page implementation

//Initialize Page @1-68793C5E
// Variables
$FileName = "";
$Redirect = "";
$Tpl = "";
$TemplateFileName = "";
$BlockToParse = "";
$ComponentName = "";

// Events;
$CCSEvents = "";
$CCSEventResult = "";

$FileName = FileName;
$Redirect = "";
$TemplateFileName = "price_list.html";
$BlockToParse = "main";
$TemplateEncoding = "UTF-8";
$PathToRoot = "./";
//End Initialize Page

//Initialize Objects @1-35033600
$DBConnection1 = new clsDBConnection1();
$MainPage->Connections["Connection1"] = & $DBConnection1;

// Controls
$Header = & new clsHeader("", "Header", $MainPage);
$Header->Initialize();
$price = & new clsGridprice("", $MainPage);
$Footer = & new clsFooter("", "Footer", $MainPage);
$Footer->Initialize();
$MainPage->Header = & $Header;
$MainPage->price = & $price;
$MainPage->Footer = & $Footer;
$price->Initialize();

$CCSEventResult = CCGetEvent($CCSEvents, "AfterInitialize", $MainPage);

$Charset = $Charset ? $Charset : "utf-8";
if ($Charset)
    header("Content-Type: text/html; charset=" . $Charset);
//End Initialize Objects

//Initialize HTML Template @1-78E0DC24
$CCSEventResult = CCGetEvent($CCSEvents, "OnInitializeView", $MainPage);
$Tpl = new clsTemplate($FileEncoding, $TemplateEncoding);
$Tpl->LoadTemplate(PathToCurrentPage . $TemplateFileName, $BlockToParse, "UTF-8");
$Tpl->block_path = "/$BlockToParse";
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeShow", $MainPage);
//End Initialize HTML Template

//Execute Components @1-351F985C
$Header->Operations();
$Footer->Operations();
//End Execute Components

//Go to destination page @1-D05E8BCC
if($Redirect)
{
    $CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
    $DBConnection1->close();
    header("Location: " . $Redirect);
    $Header->Class_Terminate();
    unset($Header);
    unset($price);
    $Footer->Class_Terminate();
    unset($Footer);
    unset($Tpl);
    exit;
}
//End Go to destination page

//Show Page @1-34E4C36F
$Header->Show();
$price->Show();
$Footer->Show();
$Tpl->block_path = "";
$Tpl->Parse($BlockToParse, false);
$main_block = $Tpl->GetVar($BlockToParse);
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeOutput", $MainPage);
if ($CCSEventResult) echo $main_block;
//End Show Page

//Unload Page @1-6C16960A
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
$DBConnection1->close();
$Header->Class_Terminate();
unset($Header);
unset($price);
$Footer->Class_Terminate();
unset($Footer);
unset($Tpl);
//End Unload Page


?>
